﻿using ExcelConfig;
using System;
using System.Linq;
using tozhang.sdk;
using txcloud.sdk.Lighthouse;

namespace cn.tozhang.linksms.data.datainit.firewall
{
    internal class init_runner
    {

        public static int OpenDBPort()
        {
            var ip = NetworkAPI.ReadInternetIP();
            var firewallkey = AppConfig.Text("防火墙标识");

            var app = new Lighthouse();
            var firewall = app.ReadFirewall();
            var info = firewall.Rules.FirstOrDefault(t => t.FirewallRuleDescription == firewallkey);
            if (info != null)
            {
                if (info.CidrBlock.Equals(ip))
                {
                    return 1; //已更新，推出
                }
                info.CidrBlock = ip;
                app.UpdateFirewall(firewall);
                return 2;
            }
            return 0;
        }
    }
}
